package com.zbiti.anvil.basic.module.business.rest.controller;


import com.zbiti.anvil.basic.module.business.api.domain.Book2Domain;
import com.zbiti.anvil.basic.module.business.api.domain.BookCategory2Domain;
import com.zbiti.anvil.basic.module.business.api.generator.domain.BookCategory2GeneratorDomain;
import com.zbiti.anvil.basic.module.business.api.service.IBookCategory2Service;
import com.zbiti.module.common.api.page.PageDomain;
import com.zbiti.module.common.api.service.IBaseService;
import com.zbiti.module.common.rest.controller.IBaseController;
import com.zbiti.sdk.common.domain.RestDomain;
import com.zbiti.sdk.common.utils.AssertUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * book_category2对外Rest风格Controller
 *
 * @author generator
 * @date 2025-04-08 12:17:44
 */
@Tag(name = "book_category2")
@RestController
@RequestMapping("/system/book_category2")
public class BookCategory2Controller implements IBaseController<BookCategory2Domain> {

    /**
    * 操作服务对象
    */
    @Autowired
    private IBookCategory2Service iBookCategory2Service;



    @Operation(
            summary = "【物理删除】根据ID删除"
    )
    @PreAuthorize("@ss.hasDeletePerm()")
    @RequestMapping(
            value = {"deleteById"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<Integer> deleteById(@RequestParam("id") String id) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        AssertUtils.assertNotEmpty(id, "参数ID不可以为空");
        return RestDomain.success(this.getIBaseService().deleteById(id));
    }

    @Operation(
            summary = "插入一条记录"
    )
    @PreAuthorize("@ss.hasInsertPerm()")
    @RequestMapping(
            value = {"insert"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<Integer> insert(BookCategory2Domain bean) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        AssertUtils.assertNotNull(bean, "保存的对象不可以为空");
        return RestDomain.success(this.getIBaseService().insert(bean));
    }

    @Operation(
            summary = "根据ID查询"
    )
    @PreAuthorize("@ss.hasSearchPerm()")
    @RequestMapping(
            value = {"/selectById"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<BookCategory2Domain> selectById(@RequestParam("id") String id) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        AssertUtils.assertNotEmpty(id, "参数ID不可以为空");
        return RestDomain.success(this.getIBaseService().selectById(id));
    }

    @Operation(
            summary = "根据Map参数分页查询"
    )
    @PreAuthorize("@ss.hasSearchPerm()")
    @RequestMapping(
            value = {"/search"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<PageDomain<BookCategory2Domain>> search(@RequestParam MultiValueMap<String, Object> params) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        return RestDomain.success(this.getIBaseService().selectPageByMap(this.getMap(params)));
    }

    @Operation(
            summary = "根据ID修改记录"
    )
    @PreAuthorize("@ss.hasUpdatePerm()")
    @RequestMapping(
            value = {"updateById"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<Integer> updateById(@RequestBody BookCategory2Domain entity) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        AssertUtils.assertNotNull(entity, "更新对象不可以为空");
        return RestDomain.success(this.getIBaseService().updateById(entity));
    }

    @Operation(
            summary = "插入或更新一条记录"
    )
    @PreAuthorize("@ss.hasModifyPerm()")
    @RequestMapping(
            value = {"insertOrUpdate"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<Integer> insertOrUpdate(@RequestBody BookCategory2Domain bean) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        AssertUtils.assertNotNull(bean, "新增或更新对象不可以为空");
        return RestDomain.success(this.getIBaseService().insertOrUpdate(bean));
    }

    @Operation(
            summary = "根据实体对象分页查询"
    )
    @PreAuthorize("@ss.hasSearchPerm()")
    @RequestMapping(
            value = {"/searchByEntity"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<PageDomain<BookCategory2Domain>> searchByEntity(@RequestBody BookCategory2Domain paramEntity) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        return RestDomain.success(this.getIBaseService().selectPageByEntityAndPage(paramEntity, this.buildPageParamFromRequest()));
    }

    @Operation(
            summary = "根据Map参数不分页查询"
    )
    @PreAuthorize("@ss.hasSearchPerm()")
    @RequestMapping(
            value = {"/searchAll"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<List<BookCategory2Domain>> searchAll(@RequestParam MultiValueMap<String, Object> params) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        return RestDomain.success(this.getIBaseService().selectByMapWithOrder(this.getMap(params)));
    }

    @Operation(
            summary = "【物理删除】根据ID删除"
    )
    @PreAuthorize("@ss.hasDeletePerm()")
    @RequestMapping(
            value = {"deleteByIdJoin"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public RestDomain<Integer> deleteByIdJoin(@RequestParam("id") Integer id) {
        AssertUtils.assertNotNull(this.getIBaseService(), "服务未启用");
        // 调用 Service 层方法
        int result = iBookCategory2Service.deleteCategoryAndBooks(id);

        return RestDomain.success(result);
    }





    /**
     * 获取通用操作Service
     *
     * @return 操作Service
     */
    @Override
    public IBaseService<BookCategory2Domain> getIBaseService() {
        return iBookCategory2Service;
    }

}
